/*
 * Copyright (c): IT@M - Dienstleister f�r Informations- und Telekommunikationstechnik
 * der Landeshauptstadt M�nchen, 2012
 */
package de.muenchen.bean;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @author IT@M/A23 Michael Prankl
 * @version 1 <br/>
 *          Jun 26, 2012
 */
public class BaseBean implements Cloneable {

    
    /**
     * Setzt leerString auf Null.
     * @param s zu prüfender String
     * @return geprüfter String
     */
    public String setNullIfEmpty(String s) { 
        String sTemp = s;
        if (s != null) {
            sTemp = sTemp.trim();
            if ("".equals(sTemp)) {
                return null;
            }
            
        }
        return sTemp;
    }
    
    /**
     * Method to generate a SHA Hash.
     * @param input String to encode
     * @return encoded String
     */
    public String getSHA(String input) {
        try {
            MessageDigest m = MessageDigest.getInstance("SHA");
            byte[] messageDigest = m.digest(input.getBytes());
            BigInteger number = new BigInteger(1, messageDigest);
            String hashText = number.toString(16);
            while (hashText.length() < 32) {
                hashText = "0" + hashText;
            }
            return hashText;
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
    }

    

}
